﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.SERVICE.DAL;
using KPIS.GERP.SERVICE.Model;
using KPIS.GERP.SERVICE.WorkflowService.Class;

namespace KPIS.GERP.SERVICE.WorkflowService.CodeActivity
{
    using System.Activities;

    public sealed class GetInstantId : CodeActivity
    {
        public InOutArgument<Guid> WorkFlowInstantId { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            WorkFlowInstantId.Set(context, context.WorkflowInstanceId);
        }
    }

    public sealed class ExecuteCommand : CodeActivity
    {
        // Define an activity input argument of type string
        public InOutArgument<command_daemon> InCommand { get; set; }
        public InOutArgument<int> InEmpSeqBot { get; set; }
        public OutArgument<bool> Success { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            command_daemon command = InCommand.Get(context);
            int empSeqBot = InEmpSeqBot.Get(context);
            var commandDal = new Command();

            if (command.Command.cmd_status != "R" && command.Command.hrm_ps_command_dtls.start_date >= DateTime.Now && command.Command.hrm_ps_command_dtls.start_date >= DateTime.Now)
            {
                foreach(var dtls in command.Command.col_hrm_ps_command_dtls)
                {
                    if(dtls.record_status == "W")
                    {
                        CommandDaemonUtils.Dowork(dtls);
                        commandDal.UpdateDetail(dtls.cmd_dtls_seq, "U", empSeqBot);
                    }
                }
            }
        }
    }
}
